using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace AhpilyServers
{
    /// <summary>
    /// 一个需要执行的方法
    /// </summary>
    public delegate void ExcuteDelegate();
    /// <summary>
    /// 单线程池
    /// </summary>
    public class SingleExcute
    {
        public Mutex mutex;
        private static SingleExcute instance = null;
        public static SingleExcute Instance
        {
            get
            {
                lock (o)
                {
                    if (instance == null)
                        instance = new SingleExcute();
                    return instance;
                }
            }
        }
        private static string o = "111";
        private SingleExcute()
        {
            mutex = new Mutex();
        }

        public void Excute(ExcuteDelegate excuteDelegate)
        {
            lock (this)
            {
                mutex.WaitOne();
                excuteDelegate();
                mutex.ReleaseMutex();
            }
        }
    }
}
